import json

from devicetest.api import Asserts
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop


class PreTest_RK3568_Basic_Setting_5100(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面-设置-辅助功能
    # 测试步骤：
    # 1、打开高对比度文字开关或关闭开关
    # 2、打开颜色反转开关
    # 预期结果：
    # 1、开关能正常开启、关闭
    # 2、开关能正常开启、关闭

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：进入桌面，点击设置-辅助功能，打开高对比度文字开关或关闭开关')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '辅助功能')

        font_switch = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='type/Toggle', index=0))
        font_status0 = font_switch.get('checked')
        CommonOH.touchByType(self.Phone1, 'Toggle', index=0)
        Step('预期结果1：开关能正常开启、关闭')
        font_switch = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='type/Toggle', index=0))
        font_status1 = font_switch.get('checked')
        Asserts.assert_not_equal(font_status0, font_status1)
        CommonOH.touchByType(self.Phone1, 'Toggle', index=0)

        Step('步骤2：打开颜色反转开关')
        color_switch = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='type/Toggle', index=1))
        color_status0 = color_switch.get('checked')
        CommonOH.touchByType(self.Phone1, 'Toggle', index=1)
        Step('预期结果2: 开关能正常开启、关闭')
        color_switch = json.loads(CommonOH.getWidgetProperties(self.Phone1, condition='type/Toggle', index=1))
        color_status1 = color_switch.get('checked')
        Asserts.assert_not_equal(color_status0, color_status1)
        CommonOH.touchByType(self.Phone1, 'Toggle', index=1)

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
